package com.github.authcloud.server.configure.filter.zuul;

import com.github.authcloud.server.configure.checker.UserAuthRolePermission;
import com.github.authcloud.server.configure.checker.UserWhiteBlackList;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.zuul.ZuulProxyMarkerConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : zhaoxuan
 * @version : 1.0
 * @date : 2021/8/22 18:39
 * @description : ZuulAuthAutoConfigure
 */
@Configuration
@ConditionalOnClass(ZuulProxyMarkerConfiguration.class)
public class ZuulAuthAutoConfigure{

    @Bean
    @ConditionalOnMissingBean(UserAuthRolePermission.class)
    UserAuthRolePermission userAuthRolePermission() {
        return new UserAuthRolePermission();
    }

    @Bean
    @ConditionalOnMissingBean(UserWhiteBlackList.class)
    UserWhiteBlackList userWhiteBlackList() {
        return new UserWhiteBlackList();
    }

    @Bean
    @ConditionalOnBean(UserAuthRolePermission.class)
    ZuulAuthRolePermissionFilter zuulAuthRolePermissionFilter() {
        return new ZuulAuthRolePermissionFilter();
    }

    @Bean
    @ConditionalOnProperty(prefix = "auth.cloud",name = "open-white-list",havingValue = "true")
    @ConditionalOnBean(UserWhiteBlackList.class)
    ZuulWhileListFilter zuulWhileListFilter() {
        return new ZuulWhileListFilter();
    }

    @Bean
    @ConditionalOnProperty(prefix = "auth.cloud",name = "open-black-list",havingValue = "true")
    @ConditionalOnBean(UserWhiteBlackList.class)
    ZuulBlackListFilter zuulBlackListFilter() {
        return new ZuulBlackListFilter();
    }
}
